import { login as loginApi } from "@/api/login";
import { setToken, removeToken } from "@/utils";
export const login = data => {
  return async dispatch => {
    // 异步请求
    let {
      data: { token },
      message,
    } = await loginApi(data);
    if (message === "OK") {
      //登录成功
      //  1.存储到redux中
      dispatch({ type: "login/setToken", payload: token });
      // 2.存储到本地
      // localStorage.setItem('geek-token',token)
      setToken(token);
    }
  };
};
// 退出登录
export const logout = () => {
  return dispatch => {
    //  清除token redux
    dispatch({ type: "clearToken" });
    // 清除 token
    removeToken();
    // 清除个人信息
    dispatch({ type: "clearUserInfo" });
  };
};
